<?php

/**
 * winbinder 패키지 
 * 
 * 
 * @package php.ui.winbinder
 */


/**
 * WBTreeView
 *
 * @package php.ui.winbinder
 */
class WBTreeView extends WBControl {
	/**
	 * 생성자 
	 * 
	 * @param array $options
	 */ 
	public function __construct($options = array()) { 
		$options['class'] = TreeView;

		parent::__construct($options);
	}

	/**
	 * 객체 생성 초기화 메소드 구현 
	 * 
	 * line 을 체크한다. 
	 * 
	 * @see WBControl#initCreate()
	 */
	public function initCreate() { 
		parent::initCreate();

		if (!isset($this->line)) $this->setOption('line', true);
	}

	/**
	 * Component 초기화 구현 
	 * 
	 * @see WBControl#initComponent()
	 */
	public function initComponent() { 
		parent::initComponent();

		if (isset($this->line))		$this->setLine($this->getOption('line'));
		if (isset($this->items))	$this->setItems($this->getOption('items'));
		if (isset($this->image))	$this->setImage($this->getOption('image'));
	}

	/**
	 * 라인 설정 
	 *
	 * @return boolean 
	 */
	public function setLine($isLine = false) { 
		return $this->setStyle(WBC_LINES, $isLine);
	}

	/**
	 * Node 생성 
	 * 
	 * <code>
	 * $options = array(
	 *		'caption' => '',
	 *		'value' => '',
	 *		'where' => '',
	 *		'image' => '',
	 *		'selectedimage' => '',
	 *		'insertiontype' => '',
	 * );
	 *
	 * </code>
	 * 
	 * @param array $opt 
	 * @return WBTreeNode 
	 */
	public function createNode($opt = array()) {
		
		$arr = array(
			$opt['caption'],	
			isset($opt['value']) ? $opt['value'] : 0,	
			isset($opt['where']) ? $opt['where'] : 0,	
			isset($opt['image']) ? $opt['image'] : -1,	
			isset($opt['selectedimage']) ? $opt['selectedimage'] : -1,	
			isset($opt['type']) ? $opt['type'] : 0,	
		);

		$item = $this->createItems(array($arr));
		
		$node = new WBTreeNode(array('tree' => $this, 'instance' => $item));
		
		return $node;
	}

	/**
	 * RootNode 생성  
	 * 
	 * @param array $options
	 * @return WBTreeNode
	 */
	public function createRoot($options = array()) { 
		$options['type'] = 0;

		return $this->createNode($options);
	}

	/**
	 * 선택되어이 TreeNode 얻어오기 
	 * 
	 * @return WBTreeNode
	 */
	public function selectedNode() { 
		return new WBTreeNode(array('tree' => $this, 'instance' => $this->getSelected()));
	}

	/**
	 * Tree 전체 아이템 지우기 
	 * 
	 * @return boolean
	 */
	public function deleteNodeAll() { 
		return $this->deleteItems();
	}
}

?>